package com.ops.memcache.core;

import net.sf.ehcache.Cache;
import net.sf.ehcache.Element;

import java.io.Serializable;
import java.util.List;

/**
 * lenovo
 * 2017/5/10
 * untitled
 */
public class EHCache implements ICache  {
	private Cache cache;

	public EHCache(Cache cache) throws Exception {
		this.cache = cache;
	}

	public void put(ICacheElement element) throws Exception {
		this.cache.put(new Element(element.getKey(), element.getValue()));
	}

	public void put(Serializable key, Serializable value) throws Exception {
		EHCacheElement element = new EHCacheElement(key, value);
		this.put(element);
	}

	public ICacheElement get(Serializable key) throws Exception {
		Element element = this.cache.get(key);
		return element == null?null:new EHCacheElement(element);
	}

	public boolean remove(Serializable key) throws Exception {
		return this.cache.remove(key);
	}

	public void removeAll() throws Exception {
		this.cache.removeAll();
	}

	public String getName() throws Exception {
		return this.cache.getName();
	}

	public int getStatus() throws Exception {
		return this.cache.getStatus().intValue();
	}

	public List getKeys() throws Exception {
		return this.cache.getKeys();
	}

	public int getSize() throws Exception {
		return this.cache.getSize();
	}

	public long getHitCount() throws Exception {
		return this.cache.getStatistics().getCacheHits();
	}

	public long getMissCount() throws Exception {
		return this.cache.getStatistics().getCacheMisses();
	}
}
